package cn.tsoft.sample.utils;

import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;

import cn.tsoft.sample.service.HelloService;
import cn.tsoft.sample.service.impl.HelloServiceImpl;

public class HelloServiceFactory implements ServiceFactory{
	private int usageCounter = 0; 
	
	public Object getService(Bundle bundle, ServiceRegistration registration) {
		System.out.println("Create objectof HelloService for " + bundle.getSymbolicName());  
		usageCounter++;  
		System.out.println("Number ofbundles using service " + usageCounter);  
		HelloService helloService = new HelloServiceImpl();  
		return helloService;  
	}

	public void ungetService(Bundle bundle, ServiceRegistration registration,
			Object service) {
		System.out.println("Release objectof HelloService for " + bundle.getSymbolicName());  
		usageCounter--;  
		System.out.println("Number ofbundles using service " + usageCounter);  
	}

}
